package com.miya.demo.handler.order;

import com.miya.demo.handler.order.handler.DataInitOrderHandler;
import com.miya.demo.handler.order.handler.DataPersistenceOrderHandler;
import com.miya.demo.handler.order.handler.PreCheckOrderHandler;
import com.miya.demo.handler.order.handler.PromotionOrderHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 订单责任链配置
 *
 * @author CaiXiaowei
 * @date 2022/09/30
 */
@Configuration
@RequiredArgsConstructor
public class OrderChainConfig {

    private final DataInitOrderHandler orderDataInitHandler;

    @Resource
    private DataPersistenceOrderHandler orderDataPersistenceHandler;

    @Resource
    private PreCheckOrderHandler orderPreCheckHandler;

    @Resource
    private PromotionOrderHandler orderPromotionHandler;

    @Bean("orderHandlerPipeline")
    OrderHandlerPipeline<OrderContexts> orderHandlerPipeline() {

        OrderHandlerPipeline<OrderContexts> createOrderHandlerPipeline = new OrderHandlerPipeline();
        createOrderHandlerPipeline.addLast(orderDataInitHandler);
        createOrderHandlerPipeline.addLast(orderPreCheckHandler);
        createOrderHandlerPipeline.addLast(orderPromotionHandler);
        createOrderHandlerPipeline.addLast(orderDataPersistenceHandler);
        return createOrderHandlerPipeline;
    }

}

